﻿using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
using System.Configuration;
using System.Windows;

namespace EntLib6DAABInCode
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {
        protected override void OnStartup(StartupEventArgs e)
        {
            var databaseSettings = new DatabaseSettings();
            databaseSettings.ProviderMappings.Add(new DbProviderMapping(DbProviderMapping.DefaultSqlProviderName, typeof(Microsoft.Practices.EnterpriseLibrary.Data.Sql.SqlDatabase)));
            databaseSettings.DefaultDatabase = "AdventureWorks";

            var connectionStringsSection = new ConnectionStringsSection();
            connectionStringsSection.ConnectionStrings.Add(new ConnectionStringSettings("AdventureWorks", "Data Source=.;User ID=sa; Password=sql; Initial Catalog=AdventureWorks2012", DbProviderMapping.DefaultSqlProviderName));

            var dictionaryConfigurationSource = new DictionaryConfigurationSource();
            dictionaryConfigurationSource.Add(DatabaseSettings.SectionName, databaseSettings);
            dictionaryConfigurationSource.Add("connectionStrings", connectionStringsSection);

            DatabaseFactory.SetDatabaseProviderFactory(new DatabaseProviderFactory(dictionaryConfigurationSource), false);

            base.OnStartup(e);
        }
    }
}